package demo4;

public class Computer {
    public void openComputer(){
        System.out.println("打开电脑！");
    }
    public void closeComputer(){
        System.out.println("关闭电脑！");
    }
    public static void useDevice(USB usb){
        usb.openDevice();
        if (usb instanceof Keyboard){//向下类型转换
            Keyboard keyboard = (Keyboard) usb;
            keyboard.input();
        }else if (usb instanceof Mouse){
            Mouse mouse = (Mouse) usb;
            mouse.click();
        }
        usb.closeDevice();
    }

    public static void main(String[] args) {
        Computer computer = new Computer();
        useDevice(new Keyboard());
        System.out.println("============");
        useDevice(new Mouse());
    }
}
